package com.exam.tencent;

import java.util.Arrays;
import java.util.Scanner;

/**
 * date:
 * description:
 */
public class Solution3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine().trim());
        String str = scanner.nextLine().substring(0, n);
        int len = str.length();
        long w = 0;
        long v = 0;
        for (int i = 0; i < len; i++) {
            if(str.charAt(i) == '1'){
                v += i + 1;
            }
        }
        long res = v - w;
        for (int i = 0; i < len; i++) {
            if(str.charAt(i) == '0'){
                w += i + 1;
            }else{
                v -= i + 1;
            }
            res = Math.min(res, Math.abs(v - w));
        }
        System.out.println(res);
    }
}
